/**
 *
 * Escola
 * 19/05/2012 - 15:41:42
 *
 */
package escola.modelo;





/**
 * @author Jonathan
 *
 */
public abstract class AbstractModel implements Comparable<AbstractModel> {
	
	private StringBuilder buffer;
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if ((obj == null) || !(getClass().isInstance(obj))) {
			return false;
		}
		if (getId() == null || ((AbstractModel) obj).getId() == null) {
			return false;
		}
		return this.getId().equals(((AbstractModel) obj).getId());
	}
	
	@Override
	public int compareTo(AbstractModel obj) {
		if (obj == null) {
			return 1;
		}
		if (getId() != null && obj.getId() != null) {
			return getId().compareTo(obj.getId());
		}
		if (getId() == null && obj.getId() == null) {
			return 0;
		}
		return getId() == null ? -1 : 1;
	}
	
	@Override
	public int hashCode() {
		if (this.getId() == null) {
			return super.hashCode();
		}
		return this.getId().hashCode();
	}
	
	public int getHashCode() {
		return hashCode();
	}
	
	protected StringBuilder getBuffer() {
		if (buffer == null) {
			buffer = new StringBuilder();
		}
		return buffer;
	}
	
	public abstract Integer getId();

}
